package cn.edu.buaa.cnsatm.traffic_big_data_server.util;
/**
 * @author:  LX
 * @description:用于字符串处理
 * @date:2019/10/14
 */
public class StringUtil {
    public static void main(String args[]){
        System.out.print(javaArrayStringToSQLSetString("[a,b,c,d,e]"));
    }
    public static String javaArrayStringToSQLSetString (String javaArrayStringSet){
        /**
         * @author:  LX
         * @description:用于将形如"a,b,c,d,e"类型代表数组的字符串转化为"('a','b','c','d','e')"，便于处理SQL中的IN字段
         * @date:2019/10/14
         */
        /*去除两端中括号*/
        String javaArrayStringSetWithoutBracket = new String(javaArrayStringSet);
        /*以逗号分割机场，存放在数组中*/
        String[] spiltAirport = javaArrayStringSetWithoutBracket.split(",");
        String SQLSetString =  "(";
        for(int i = 0; i < spiltAirport.length; i++){
            SQLSetString = SQLSetString + "\'" + spiltAirport[i] + "\'";
            if(i != spiltAirport.length - 1){SQLSetString = SQLSetString + ",";}
        }
        SQLSetString = SQLSetString + ")";
        return SQLSetString;
    }
}
